package com.china.produce.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/8/21
 */
@Api(tags = "cache模块")
@RequestMapping("/cache")
@RestController
public class CacheController {

    @ApiImplicitParam(name = "id", value = "id", required = true)
    @RequestMapping("/info/{id}")
    @Cacheable(value = "info", key = "#id")
    public String getInfo(@PathVariable("id") Integer id) throws IOException {

        System.out.println("11111111");
        return "info : " + id;
    }

    @RequestMapping("/update/{id}/{value}")
    @CachePut(value = "info", key = "#id")
    public String updateInfo(@PathVariable("id") Integer id, @PathVariable("value") String value) {

        System.out.println("222");

        return "info : " + value;
    }

    @RequestMapping("/delete/{id}")
    @CacheEvict(value = "info", key = "#id")
    public String deleteInfo(@PathVariable("id") Integer id) {

        return "delete " + id + " success";
    }
}
